@extends('admin.common.main')

@section('css')
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
@endsection
@section('cnt')
    <div class="layui-form layuimini-form" lay-filter="example">
        @csrf
        <div class="layui-form-item">
            <label class="layui-form-label required">真实姓名</label>
            <div class="layui-input-block">
                <input type="text" name="truename" id="truename"  lay-verify="required"  value="{{$user->truename}}" class="layui-input">
            </div>
        </div>
{{--        <input type="hidden" name="id" id="id" value="{{$user->id}}" >--}}
        <div class="layui-form-item">
            <label class="layui-form-label required">账号</label>
            <div class="layui-input-block">
                {{$user->username}}
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="sex" value="先生" title="先生" {{($user->sex=='先生')?"checked=''":0}}>
                <input type="radio" name="sex" value="女士" title="女士" {{$user->sex=='女士'?"checked=''":0}}>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="password" name="password" id="password"    value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-block">
                <input type="password" name="password_confirmation" id="password_confirmation"   class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">邮箱</label>
            <div class="layui-input-block">
                <input type="email" name="email"  lay-verify="email" id="email"  value="{{$user->email}}" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">手机号</label>
            <div class="layui-input-block">
                <input type="number" name="phone" id="phone" value="{{$user->phone}}"  lay-verify="required|phone|number" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认修改</button>
            </div>
        </div>
    </div>
@endsection

@section('js')
    <script>
        layui.use(['form','upload','http','table','tableSelect'], function () {
            var form = layui.form,
                layer = layui.layer,
                http  = layui.http,
                $ = layui.$;
            //监听提交
            form.on('submit(saveBtn)', function (data) {
                if(data.field.confirmation_password && data.field.password){
                    if(data.field.confirmation_password !== data.field.password ){
                        layer.msg("两次密码不相同",{time:1000,icon:2});
                        return false;
                    }
                }
                http.httpajax('{{route('admin.user.edit',['id'=>$user->id])}}', data.field,"PUT",function(res) {
                    if(res.code === 200){
                        layer.msg(res.msg,{time:1000,icon:1},function(){
                            // 关闭弹出层
                            layer.close();
                            window.parent.location.reload();//刷新父页面
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        });
                    }else{
                        layer.msg(res.errors,{time:1000,icon:2});
                    }
                });
            });
        });
    </script>
@endsection

